﻿Imports System.Data.SqlClient
Imports DTO

Public Class CacLoaiCaDao

    Public Shared Function LayDSDanhSach() As SqlDataAdapter
        Dim dt As New DataTable
        Dim cn As SqlConnection = DataProvider.ConnectioData
        Dim cmd As SqlCommand = DataProvider.CommandData("sp_laydanhsachcacloaica", cn)

        Dim da As New SqlDataAdapter(cmd)
        cn.Close()
        Return da
    End Function

    Public Shared Function LayDanhSach() As DataTable
        Dim dt As New DataTable
        Dim cn As SqlConnection = DataProvider.ConnectioData
        Dim cmd As SqlCommand = DataProvider.CommandData("sp_laydanhsachcacloaica", cn)

        Dim da As New SqlDataAdapter(cmd)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Shared Sub ThemCa(ByVal ca As CacLoaiCaDto)

        Dim cn As SqlConnection = DataProvider.ConnectioData
        Dim cmd As SqlCommand = DataProvider.CommandData("sp_themcacloaica", cn)

        cmd.Parameters.Add("@maca", SqlDbType.NVarChar)
        cmd.Parameters("@maca").Value = ca.MaCa

        cmd.Parameters.Add("@tenca", SqlDbType.NVarChar)
        cmd.Parameters("@tenca").Value = ca.TenCa

        cmd.Parameters.Add("@giovao", SqlDbType.Time)
        cmd.Parameters("@giovao").Value = ca.GioVao

        cmd.Parameters.Add("@giora", SqlDbType.Time)
        cmd.Parameters("@giora").Value = ca.GioRa

        cmd.Parameters.Add("@nghitu", SqlDbType.Time)
        cmd.Parameters("@nghitu").Value = ca.NghiTu

        cmd.Parameters.Add("@nghiden", SqlDbType.Time)
        cmd.Parameters("@nghiden").Value = ca.NghiDen

        cmd.ExecuteNonQuery()

        cn.Close()

    End Sub

    Public Shared Sub SuaCa(ByVal ca As CacLoaiCaDto)

        Dim cn As SqlConnection = DataProvider.ConnectioData
        Dim cmd As SqlCommand = DataProvider.CommandData("sp_suacacloaica", cn)

        cmd.Parameters.Add("@maca", SqlDbType.NVarChar)
        cmd.Parameters("@maca").Value = ca.MaCa

        cmd.Parameters.Add("@tenca", SqlDbType.NVarChar)
        cmd.Parameters("@tenca").Value = ca.TenCa

        cmd.Parameters.Add("@giovao", SqlDbType.Time)
        cmd.Parameters("@giovao").Value = ca.GioVao

        cmd.Parameters.Add("@giora", SqlDbType.Time)
        cmd.Parameters("@giora").Value = ca.GioRa

        cmd.Parameters.Add("@nghitu", SqlDbType.Time)
        cmd.Parameters("@nghitu").Value = ca.NghiTu

        cmd.Parameters.Add("@nghiden", SqlDbType.Time)
        cmd.Parameters("@nghiden").Value = ca.NghiDen

        cmd.ExecuteNonQuery()

        cn.Close()

    End Sub

    Public Shared Sub XoaCa(ByVal maca As String)

        Dim cn As SqlConnection = DataProvider.ConnectioData
        Dim cmd As SqlCommand = DataProvider.CommandData("sp_xoacacloaica", cn)

        cmd.Parameters.Add("@maca", SqlDbType.NVarChar)
        cmd.Parameters("@maca").Value = maca

        cmd.ExecuteNonQuery()

        cn.Close()

    End Sub
End Class
